//
//  DBHistoryDataSr03.h
//  CareRingApp
//
//  Created by Linktop on 2022/8/15.
//

#import <Foundation/Foundation.h>
#import "SRHistoryDataSR03.h"
#import "NSMutableDictionary+SleepUsed.h"
NS_ASSUME_NONNULL_BEGIN
@class FMDatabase;
@class DBSleepData;

@interface DBHistoryDataSr03 : NSObject

@property(assign, nonatomic)int cId;
@property(strong, nonatomic)NSNumber *time; // 时间戳

@property(strong, nonatomic)NSString *macAddress; //设备Mac地址

@property(strong, nonatomic) NSNumber *deviceModifyHeartRate; // 设备补偿后的心率
@property(strong, nonatomic) NSNumber * heart_ori_1,  * heart_ori_2, * heart_ori_3; // 原始心率 1 2 3
@property(strong, nonatomic)NSNumber *hrv; // 预留

@property(strong, nonatomic) NSNumber *bloodOxygen;
@property(strong, nonatomic) NSNumber *skinTemp;
@property(strong, nonatomic) NSNumber *steps; // 累加值
@property(strong, nonatomic) NSNumber *soprtTimes; // 运动计数 五分钟内的运动计数
@property(assign, nonatomic) BOOL isSos;
@property(strong, nonatomic) NSNumber *dataUuid; // 记录唯一标识
@property(strong, nonatomic) NSNumber *isWear; //是否佩戴
@property(assign, nonatomic)SR03HIS_MEASURE_TYPE measureType;  // 测量模式
@property(assign, nonatomic)BOOL devFixStep;
@property(assign, nonatomic)BOOL isSportMode;
@property(strong, nonatomic)NSNumber *respiratory;
@property(strong, nonatomic)NSNumber *battery;
/*
 * SR03HIS_MEASURE_TYPE_HR : heart_ori_3 有值, bloodOxygen 无值
 * SR03HIS_MEASURE_TYPE_OXYGEN : heart_ori_3 无值, bloodOxygen 有值
 */

//创建数据库
+(void)createTable;

+(void)queryBy:(NSString * _Nonnull)macAdres
         Begin:(NSDate *)beginDate
           End:(NSDate *)endDate
OrderBeTimeDesc:(BOOL)isDesc
      Cpmplete:(void(^)(NSMutableArray<DBHistoryDataSr03 *> *results))cmpBlk;



// 为睡眠计算的查询
+(void)queryForSleepCalcBy:(NSString * _Nonnull)account Begin:(NSDate *)beginDate End:(NSDate *)endDate OrderBeTimeDesc:(BOOL)isDesc NeedCalcRestHr:(BOOL)needCalcRestHr Cpmplete:(void(^)(NSMutableArray<NSMutableDictionary *> *results, NSMutableArray<DBHistoryDataSr03 *> *objArray))cmpBlk;


/// 批量插入
/// @param macAdres 当前账户
/// @param dataArray 数据数组
/// @param cmpBlk 回调
+(void)mutiInsert:(NSString * _Nonnull)macAdres Array:(NSArray <SRHistoryDataSR03 *> *)dataArray       Cpmplete:(void(^)(NSMutableArray<SRHistoryDataSR03 *> *dataArray, BOOL isSucc))cmpBlk;


// 批量删除
+(void)deleteFromTime:(NSTimeInterval)time macAdres:(NSString *)macAdres Cpmplete:(void(^)( BOOL isSucc))cmpBlk;
+(NSNumber *)querySyncminTimeBymacAdres:(NSString *)macAdres Db:(FMDatabase * _Nonnull)db;

+(void)queryueryRestHrBymacAdres:(NSString *)macAdres Date:(NSDate *)date CMP:(void(^)(NSNumber *restHr ))cmpBlk;

/// Query resting heart rate with sleep object
/// - Parameters:
///   - sleepObj: sleep object
///   - cmpBlk: return result. restHr -- lowest heart rate during sleep
+(void)queryueryRestHrBySleepObj:(DBSleepData *)sleepObj CMP:(void(^)(NSNumber *restHr ))cmpBlk;

// 查询电量列表
/// To use this interface, please upgrade the device firmware.  SR09W  > 1.3.8 , SR09N > 2.2.2
+(void)queryBatteryList:(NSString * _Nonnull)macAdres Begin:(NSDate *)beginDate End:(NSDate *)endDate OrderBeTimeDesc:(BOOL)isDesc Cpmplete:(void(^)(NSMutableArray<NSDictionary *> *results))cmpBlk;


+(void)dropTable;

+(void)clearColumnBy:(NSString *)macAddress DB:(FMDatabase * _Nonnull )db;

+(void)queryForSportBy:(NSString * _Nonnull)macAddress Begin:(NSDate *)beginDate End:(NSDate *)endDate OrderBeTimeDesc:(BOOL)isDesc Cpmplete:(void(^)(NSMutableArray<NSDictionary *> *results))cmpBlk;

#if DEBUG
+(void)debugInsert:(NSString * _Nonnull)macAdres Array:(NSArray <NSDictionary *> *)resArray       Cpmplete:(void(^)( BOOL isSucc))cmpBlk;
#endif
@end

NS_ASSUME_NONNULL_END
